package com.shoe.controller;

import com.shoe.pojo.ShoeCollectShow;
import com.shoe.service.ShoeCollectService;
import com.shoe.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@CrossOrigin
public class CollectController {

    @Autowired
    ShoeCollectService shoeCollectService;

  /*  @RequestMapping("collect")
    @ResponseBody
    public int add(ShoeCollect shoeCollect){
        return shoeCollectService.add(shoeCollect);
    }*/

    @GetMapping("collectAll")
    @ResponseBody
    public ResponseResult selectAll(){
       List<ShoeCollectShow> shoeCollectShowList = shoeCollectService.selectAll();
       if (shoeCollectShowList != null){
           ResponseResult responseResult = new ResponseResult();
           responseResult.setCode(1);
           responseResult.setMessage("查询成功");
           responseResult.setData(shoeCollectShowList);
           return responseResult;
       }
        return null;
    }
    @GetMapping("collectPage")
    @ResponseBody
    public ResponseResult selectPage(@RequestParam int currPage,@RequestParam int pageSize){
        ResponseResult shoeCollectShow = shoeCollectService.selectAll(currPage,pageSize);
        return shoeCollectShow;
    }

    @GetMapping("deletebyid")
    @ResponseBody
    public int deleteById(Long collectid){
        System.out.println(collectid);
        int a = shoeCollectService.deleteById(collectid);
        return  a;
    }


    @RequestMapping("addCollect/{userId}/{goodId}")
    public String addCollect(@PathVariable String userId,@PathVariable String goodId){
        System.out.println(userId);
        System.out.println(goodId);
        Long id = Long.valueOf(userId);
      int a =  shoeCollectService.addCollect(Long.valueOf(userId),Long.valueOf(goodId));
      if(a == 1){
          return "redirect:http://localhost:63343/qiguai/html/single-goods.html?id="+goodId;
      }else {
          System.out.println("添加失败");
      }
      return null;
    }


    @RequestMapping("deleteCollect/{userId}/{goodId}")
    public String deleteCollect(@PathVariable String userId,@PathVariable String goodId){
        System.out.println(userId);
        System.out.println(goodId);
        Long id = Long.valueOf(userId);
        int a =  shoeCollectService.deleteCollect(Long.valueOf(userId),Long.valueOf(goodId));
        if(a == 1){
            return "redirect:http://localhost:63343/qiguai/html/single-goods.html?id="+goodId;
        }else {
            System.out.println("删除失败");
        }
        return null;
    }



    @GetMapping("selectbyuserId")
    @ResponseBody
    public ResponseResult selectByUserId(String cookieId, @RequestParam int currPage, @RequestParam int pageSize){
        System.out.println(cookieId);
        System.out.println(currPage);
        System.out.println(pageSize);
        ResponseResult responseResult = shoeCollectService.selectByUserId(Long.parseLong(cookieId),currPage,pageSize);
        return responseResult;
    }

    @RequestMapping("judge")
    @ResponseBody
    public int judge(@RequestParam String userId ,@RequestParam String goodId){

        System.out.println("1111");
        int x = shoeCollectService.selectId(Long.valueOf(userId),Long.valueOf(goodId));
        return x;
    }

}
